﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyDMS.DAL;
using System.Linq;

public partial class admin_Department : PageBaseClass
{
    MyDMSEntity myDmsEntity=new MyDMSEntity();
    protected void Page_Load(object sender, EventArgs e)
    {
        List<Department> departments = myDmsEntity.Department.Where(r => r.Office_Code == Author.office_Code).ToList();
        this.gvDept.DataSource = departments;
        this.gvDept.DataBind();
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        Department dept = new Department();
        dept.Department_Name = txtDeptName.Text;
        dept.Location = txtLocation.Text;
        dept.Address = txtAddress.Text;
        dept.Office_Code = Author.office_Code;
        dept.Creation_Date = DateTime.Now;
        dept.Updation_Date = DateTime.Now;

        myDmsEntity.Department.AddObject(dept);
        if (myDmsEntity.SaveChanges()>0)
        {
            lblMessage.Text = "Saved Successfully";
        }
        else
        {
            lblMessage.Text = "Error!";
        }
        lblMessage.Visible = true;
    }
    protected void gvDept_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvDept.PageIndex = e.NewPageIndex;
        DataBind();
    }
}
